#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import multiprocessing


def myprint(obj):
    sys.stdout.write(str(obj) + '\n')


def consumer(pipe):
    (output_p, input_p) = pipe
    input_p.close()
    while True:
        try:
            item = output_p.recv()
        except EOFError:
            break
        myprint(item)
    myprint('consumer done')


def producer(sequence, input_p):
    for item in sequence:
        input_p.send(item)


if __name__ == '__main__':
    (output_p, input_p) = multiprocessing.Pipe()
    cons_p = multiprocessing.Process(target=consumer, args=((output_p,
            input_p), ))
    cons_p.start()

    output_p.close()

    sequence = range(5)
    producer(sequence, input_p)

    input_p.close()

    cons_p.join()
